package mock_seed

import (
	"time"
	"wms/internal/model"
	"wms/pkg/database"
	"wms/pkg/logger"

	"go.uber.org/zap"
)

// InitFrozenFoodSuppliers 初始化冷链食品供应商数据
func InitFrozenFoodSuppliers() error {
	logger.Info("开始初始化冷链食品供应商数据...")
	db := database.GetDB()

	// 清空现有供应商数据
	if err := db.Exec("DELETE FROM suppliers").Error; err != nil {
		logger.Error("清空供应商数据失败", zap.Error(err))
		return err
	}

	// 冷链食品供应商列表
	suppliers := []model.Supplier{
		{
			Code:    "SUP001",
			Name:    "北极星冷鲜肉业有限公司",
			Contact: "张经理",
			Phone:   "13800138001",
			Email:   "contact@polarmeat.com",
			Address: "北京市顺义区空港物流园区冷链一号仓",
			Status:  1,
		},
		{
			Code:    "SUP002",
			Name:    "海洋之星冷冻水产有限公司",
			Contact: "李总",
			Phone:   "13900139002",
			Email:   "service@oceansea.com",
			Address: "上海市浦东新区外高桥港区冷链物流中心",
			Status:  1,
		},
		{
			Code:    "SUP003",
			Name:    "金牛畜牧冷冻食品有限公司",
			Contact: "王经理",
			Phone:   "13700137003",
			Email:   "sales@goldenbull.com",
			Address: "河北省石家庄市正定县冷链产业园",
			Status:  1,
		},
		{
			Code:    "SUP004",
			Name:    "龙腾速冻食品集团",
			Contact: "赵总",
			Phone:   "13600136004",
			Email:   "info@longfly.com",
			Address: "山东省青岛市黄岛区食品工业园",
			Status:  1,
		},
		{
			Code:    "SUP005",
			Name:    "雪域高原牦牛肉业有限公司",
			Contact: "钱总",
			Phone:   "13500135005",
			Email:   "sales@snowland.com",
			Address: "青海省西宁市城东区生物科技产业园",
			Status:  1,
		},
		{
			Code:    "SUP006",
			Name:    "银鹰禽业冷冻食品有限公司",
			Contact: "孙经理",
			Phone:   "13400134006",
			Email:   "contact@silvereagles.com",
			Address: "山东省烟台市福山区食品加工区",
			Status:  1,
		},
		{
			Code:    "SUP007",
			Name:    "丰收谷物速冻食品有限公司",
			Contact: "周总",
			Phone:   "13300133007",
			Email:   "info@harvestfood.com",
			Address: "黑龙江省哈尔滨市松北区科技创新城",
			Status:  1,
		},
		{
			Code:    "SUP008",
			Name:    "南海渔业冷冻水产品有限公司",
			Contact: "吴经理",
			Phone:   "13200132008",
			Email:   "sales@southsea.com",
			Address: "广东省湛江市霞山区渔港经济区",
			Status:  1,
		},
		{
			Code:    "SUP009",
			Name:    "冰雪速冻蔬果有限公司",
			Contact: "郑总",
			Phone:   "13100131009",
			Email:   "service@icevegetables.com",
			Address: "河南省郑州市郑东新区物流园区",
			Status:  1,
		},
		{
			Code:    "SUP010",
			Name:    "鲜活冷链物流有限公司",
			Contact: "马经理",
			Phone:   "13000130010",
			Email:   "logistics@freshlife.com",
			Address: "浙江省杭州市萧山区临江物流中心",
			Status:  1,
		},
	}

	// 添加供应商
	now := time.Now()
	for i, supplier := range suppliers {
		supplier.CreatedAt = now
		supplier.UpdatedAt = now
		supplier.ID = uint(i + 1) // 确保ID从1开始连续

		// 直接创建供应商，不检查是否存在
		if err := db.Create(&supplier).Error; err != nil {
			logger.Error("创建供应商失败", zap.String("name", supplier.Name), zap.Error(err))
			return err
		}
		logger.Info("创建供应商成功", zap.String("name", supplier.Name))
	}

	logger.Info("冷链食品供应商数据初始化成功")
	return nil
}
